import {defineStore} from 'pinia'

export const useUserStore = defineStore('userstore', {
    state: () => ({
        user: {
            "id": "",
            "username": "",
            "password": "",
            "phone": "",
            "nickname": "",
            "createdAt": "",
            "guanli": 0,
            "pic": null,
            "rname": "",
            "token": "",
            "code": null
        },
        ord1:{
            "startName":"",
            "endName":""
        },
    }),
    getters: {
        getUsername: (state) => state.user.username,
        getPassword: (state) => state.user.password,
        getNikename: (state) => state.user.nickname,
        getToken: (state) => state.user.token,
        getPic: (state) => state.user.pic,
        getUserId: (state) => state.user.id,
        getUserCreatedAt: (state) => state.user.createdAt,
        getUserGuanli: (state) => state.user.guanli,
        getUserRname: (state) => state.user.rname,
        getUserCode: (state) => state.user.code,
        getUser: (state) => state.user,
        getOrdStartName: (state) => state.ord1.startName,
        getOrdEndName: (state) => state.ord1.endName
    },

    actions: {
        setUsername(username) {
            this.user.username = username;
        },
        setPassword(password) {
            this.user.password = password;
        },
        setNikeName(nickname) {
            this.user.nickname = nickname;
        },
        setToken(token) {
            this.user.token = token;
        },
        setPic(pic) {
            this.user.pic = pic;
        },
        setId(id) {
            this.user.id = id;
        },
        setCreatedAt(createdAt) {
            this.user.createdAt = createdAt;
        },
        setGuanli(guanli) {
            this.user.guanli = guanli;
        },
        setRname(rname) {
            this.user.rname = rname;
        },
        setCode(code) {
            this.user.code = code;
        },
        setUser(user) {
            this.user = user;
        },
        setStartName(startName) {
            this.ord1.startName = startName;
        },
        setEndName(endName) {
            this.ord1.endName = endName
        }
    },


    persist: {
        storage: localStorage,
        key: 'userstore'
    },
    // 其他配置...

})